package middleware

import (
	"dc-go/global"
	"dc-go/model"
	"dc-go/utils"

	"github.com/gin-gonic/gin"
)

func LogOperationHandler() gin.HandlerFunc {
	return func(c *gin.Context) {
		var logOperation model.SysLogOperation
		logOperation.OperationEmpeeAcct = utils.GetEmpeeAcct(c)
		logOperation.OperationIp = c.ClientIP()
		logOperation.OperationApi = c.Request.RequestURI
		logOperation.OperationMethod = c.Request.Method
		logOperation.OperationStatus = c.Writer.Status()

		_ = global.DcDb.Create(&logOperation).Error

		c.Next()
	}
}
